package com.ethan.orika;

import com.ethan.model.Person;
import com.ethan.model.PersonDto;
import com.ethan.model.order.*;
import com.ethan.model.orderdto.OrderDetailsModel;
import com.google.common.collect.Lists;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import ma.glasnost.orika.metadata.Type;
import ma.glasnost.orika.metadata.TypeBuilder;

import java.util.List;

/**
 * @author ethan
 * create 2018-04-11 下午2:53
 * desc 递归映射
 **/
public class OrikaTest6 {
    public static void main(String[] args){


        List<TimePointCharges> timePointChargesList = Lists.newArrayList(new TimePointCharges(1,"一小时前"),new TimePointCharges(2,"两小时前"));
        AdultTgqRule adultTgqRule = new AdultTgqRule("退改签1",true,timePointChargesList);
        List<ChildTgqRule> childTgqRuleList = Lists.newArrayList(new ChildTgqRule("退改签2",true,timePointChargesList));

        List<TgqInfo> tgqInfoList = Lists.newArrayList();
        TgqInfo tgqInfo1 = new TgqInfo(1,adultTgqRule,childTgqRuleList);
        TgqInfo tgqInfo2 = new TgqInfo(2,adultTgqRule,childTgqRuleList);
        tgqInfoList.add(tgqInfo1);
        tgqInfoList.add(tgqInfo2);

        OrderDetails orderDetails = OrderDetails.builder().build();
        orderDetails.setAgentInfo(new AgentInfo("xep"));
        orderDetails.setFlightSegmentList(Lists.newArrayList(new FlightSegment(1,"csc34342")));
        orderDetails.setTgqInfoList(tgqInfoList);
        Result<OrderDetails> result = new Result<>(200,orderDetails,"");


        MapperFactory mapperFactory  =MapperFactoryHolder.mapperFactory;
        mapperFactory.classMap(OrderDetails.class,OrderDetailsModel.class)
        .field("tgqInfoList{childTgqRuleList}","tgqInfoList{childTgqRuleList}")
        .field("tgqInfoList{adultTgqRule}","tgqInfoList{adultTgqRuleModel}")
        .field("tgqInfoList{type}","tgqInfoList{type}")
        .byDefault().register();
        OrderDetailsModel orderDetails1 = mapperFactory.getMapperFacade()
                .map(result.dataBody,OrderDetailsModel.class);


//        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
////        Type<Result<OrderDetails>> fromType = new TypeBuilder<Result<OrderDetails>>() {}.build();
////        Type<Result<OrderDetailsModel>> toType = new TypeBuilder<Result<OrderDetailsModel>>() {}.build();
////        Result<OrderDetailsModel> orderDetailsModelResult = mapperFactory.getMapperFacade().map(result, fromType, toType);
//        //OrderDetailsModel orderDetailsModel = mapperFactory.getMapperFacade().map(orderDetails,OrderDetailsModel.class);
//
//        mapperFactory.classMap(OrderDetails.class,OrderDetailsModel.class)
//                .field("tgqInfoList{childTgqRuleList}","tgqInfoList{childTgqRuleList}")
//                .field("tgqInfoList{adultTgqRule}","tgqInfoList{adultTgqRuleModel}")
//                .field("tgqInfoList{type}","tgqInfoList{type}")
//                .byDefault().register();
//
//        OrderDetailsModel orderDetails1 = mapperFactory.getMapperFacade()
//                .map(result.dataBody,OrderDetailsModel.class);



        String a="";
    }
}
